<html>
<head><meta charset="utf-8"><title>Use different syntax highlighting for doc test · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Use.20different.20syntax.20highlighting.20for.20doc.20test.html">Use different syntax highlighting for doc test</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243477455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Use%20different%20syntax%20highlighting%20for%20doc%20test/near/243477455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Use.20different.20syntax.20highlighting.20for.20doc.20test.html#243477455">(Jun 22 2021 at 06:46)</a>:</h4>
<p>Hey, is there a way to have <code>rustdoc</code> highlight using a different language syntax while still considering it a doc test? That might seem odd, but the use case I have is that we want to show configuration examples which are also validated when running <code>cargo test</code>.</p>
<p>See the following example, this will only show TOML in the generated documentation, but it will be highlighted as Rust code.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">//! ```rust</span>
<span class="sd">//! # let data = r#"</span>
<span class="sd">//! key = "value"</span>
<span class="sd">//! [dependencies.serde]</span>
<span class="sd">//! optional = true</span>
<span class="sd">//! # ";</span>
<span class="sd">//! # toml::from_str::&lt;Config&gt;(data).unwrap();</span>
<span class="sd">//! ```</span>
</code></pre></div>



<a name="243485003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Use%20different%20syntax%20highlighting%20for%20doc%20test/near/243485003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Use.20different.20syntax.20highlighting.20for.20doc.20test.html#243485003">(Jun 22 2021 at 08:20)</a>:</h4>
<p>So, the basic answer is no. One thing which was suggested though was for the users to use a JS syntax highlighter on their own so they can modify the code blocks as they see fit.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>